//
//  BSMainViewController.m
//  sister
//
//  Created by 周冰烽 on 2017/2/7.
//  Copyright © 2017年 周冰烽. All rights reserved.
//

#import "BSMainViewController.h"
#import "BSEssenceViewController.h"
#import "BSNewViewController.h"
#import "BSFriendsViewController.h"
#import "BSMeViewController.h"
#import "BSTabBar.h"
#import "BSNavigationViewController.h"
@interface BSMainViewController ()

@end

@implementation BSMainViewController

+(void)initialize {
    //通过appearance统一设置所有UITabBarItem的文字属性(方法后面带有UI_APPEARANCE_SELECTOR,都可以通过此方法设置)
    NSMutableDictionary *attrs = [NSMutableDictionary dictionary];
    attrs[NSForegroundColorAttributeName] = [UIColor grayColor];
    
    NSMutableDictionary *selectAttrs = [NSMutableDictionary dictionary];
    selectAttrs[NSForegroundColorAttributeName] = [UIColor darkGrayColor];
    
    UITabBarItem *item = [UITabBarItem appearanceWhenContainedInInstancesOfClasses:@[[self class]]];
    [item setTitleTextAttributes:attrs forState:UIControlStateNormal];
    [item setTitleTextAttributes:selectAttrs forState:UIControlStateSelected];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupChildControllers];
}
-(void)setupChildControllers {
    
    [self setupChildVCWitTitle:@"精华" image:@"tabBar_essence_icon" selectImage:@"tabBar_essence_click_icon" class:[BSEssenceViewController class]];
    
    [self setupChildVCWitTitle:@"新帖" image:@"tabBar_new_icon" selectImage:@"tabBar_new_click_icon" class:[BSNewViewController class]];
    
    [self setupChildVCWitTitle:@"关注" image:@"tabBar_friendTrends_icon" selectImage:@"tabBar_friendTrends_click_icon" class:[BSFriendsViewController class]];
    
    [self setupChildVCWitTitle:@"我" image:@"tabBar_me_icon" selectImage:@"tabBar_me_click_icon" class:[BSMeViewController class]];
    [self setValue:[[BSTabBar alloc]init] forKeyPath:@"tabBar"];
    
}
-(void)setupChildVCWitTitle:(NSString *)title image:(NSString *)image selectImage:(NSString *)selectImage class:(Class)class {
    UIViewController *vc = [[class alloc]init];
    vc.tabBarItem.title = title;
    vc.tabBarItem.image = [UIImage imageNamed:image];
    vc.tabBarItem.selectedImage = [UIImage imageNamed:selectImage];
    //包装一个导航控制器,添加导航控制器为tabBarController的子控制器
    BSNavigationViewController *navi = [[BSNavigationViewController alloc]initWithRootViewController:vc];
    [self addChildViewController:navi];
}

@end
